<template>
    <div class="viewsmessages">
        <div class="viewsmessages-head">
            <span>消息</span>
        </div>
        <div class="viewsmessages-content">
            <ul>
                <li v-for="(item,index) in MessageList" :key="index">
                    <img :src="item.map.userinfo.avatar"/>
                    <div>
                        <label>
                            <span>{{item.map.userinfo.nick_name}}</span>
                            <span v-if="item.type == 'curriculumupdate'">申请预约</span>
                            <span v-else>取消预约</span>
                        </label>
                        <label>
                            <span>{{item.map.userAppointmentInfo.title}}</span>
                            <span>{{item.map.userAppointmentInfo.create_time}} {{item.map.userAppointmentInfo.start_time}}-{{item.map.userAppointmentInfo.end_time}}</span>
                        </label>
                    </div>
                    <div class="viewsmessages-content-right">
                        <label v-if="item.map.userAppointmentInfo.whether == null" class="untreated">
                            <span @click="updateConfirm(1,item.appointment_id,item.user_id,item.id,item.map.userAppointmentInfo.masterNotice_id,item.map.userAppointmentInfo.update_appointment_id,item.identity)">同意</span>
                            <span @click="updateConfirm(2,item.appointment_id,item.user_id,item.id,item.map.userAppointmentInfo.masterNotice_id,item.map.userAppointmentInfo.update_appointment_id,item.identity)">拒绝</span>
                        </label>
                        <label v-else>
                            <span v-if="item.map.userAppointmentInfo.whether">已同意</span>
                            <span v-else>已拒绝</span>
                        </label>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
export default {
    name:'viewsmessages',
    data(){
        return{
            untreated:true,
            MessageList:[],
            userinfo:JSON.parse(localStorage.getItem('userinfo')),
        }
    },
    created(){
        this.Getmessages()
    },
    methods:{
        Getmessages(){
            var data = {
                currentPage:1,
                master_id:this.userinfo.user_id,
                pageSize :20
            }
            this.$axios({
                method:'get',
                url:'http://101.37.66.151:8768/eg-api/user/masterNotice/queryListPage',
                params:data,
            }).then((res) =>{
                console.log(res.data.data,'消息中心')
                this.MessageList = res.data.data
                this.MessageList.forEach(e => {
                    var stars = e.map.userAppointmentInfo.start_time
                    var entimes = e.map.userAppointmentInfo.end_time
                    var times = stars.substring(0, stars.indexOf(' '))//截取当前日期
                    var starttime =  stars.substring(11, 16)//截取开始时间
                    var endtime =  entimes.substring(11, 16)//截取结束时间
                    e.map.userAppointmentInfo['create_time'] = times
                    e.map.userAppointmentInfo['start_time'] = starttime
                    e.map.userAppointmentInfo['end_time'] = endtime
                });
            }).catch((error) =>{
                console.log(error)
            })

        },
        updateConfirm(e,appointmentid,masterid,ids,masterNoticeid,update_appointment_id,identity){
            if(e == 1){
                var data = {
                    appointment_id : appointmentid,
                    id :ids,
                    masterNotice_id:masterNoticeid,
                    master_id:masterid,
                    stutas :2,
                    update_appointment_id:update_appointment_id,
                    update_identity:identity,
                    update_type:'curriculumupdate',
                    user_id:this.userinfo.user_id,
                    whether :true
                }
            }else{
               var data = {
                    appointment_id : appointmentid,
                    id :ids,
                    masterNotice_id:masterNoticeid,
                    master_id:masterid,
                    stutas :2,
                    update_appointment_id:update_appointment_id,
                    update_identity:identity,
                    update_type:'curriculumupdate',
                    user_id:this.userinfo.user_id,
                    whether :false
                } 
            }
            this.$axios({
                method:'POST',
                url:'http://101.37.66.151:8768/eg-api/user/userAppointment/updateConfirm',
                data:data,
            }).then((res) =>{
                console.log(res.data.data,'修改结果')
                alert(res.data.message)
            }).catch((error) =>{
                console.log(error)
            })
        }
    }
}
</script>
<style lang="less" scoped>
    .viewsmessages{
        position: relative;
        width: 100%;
        background: #ffffff;
    }
    .viewsmessages-head{
        position: relative;
        width: 90%;
        margin: 0 auto;
        height: 100px;
        display: flex;
        align-items: center;
        border-bottom: 1px solid #2DC7C8;
        span{
            width: 20%;
            height: 30px;
            line-height: 30px;
            border-left: 20px solid #2DC7C8;
            padding-left: 2%;
            color: #2DC7C8;
            font-weight: bold;
            font-size: 24px;
        }
    }
    .viewsmessages-content{
        position: relative;
        width: 90%;
        margin: 0 auto;
        margin-top: 30px;
        padding-bottom: 120px;
        ul{
            position: relative;
            width: 90%;
            margin: 0 auto;
            display: flex;
            padding: 0;
            flex-wrap: wrap;
            list-style: none;
            li{
                width: 100%;
                height: 100px;
                display: flex;
                align-items: center;
                // justify-content: center;
                border-bottom: 1px solid #f1f1f1;
                img{
                    width: auto;
                    height: auto;
                    max-width: 70%;
                    max-height: 70%;
                    border-radius: 40px;
                }
                div{
                    width: 50%;
                    height: 80px;
                    &:first-child{
                        margin-left: 4%;
                    }
                    label{
                        display: flex;
                        flex-wrap: wrap;
                        height: 40px;
                        line-height: 40px;
                        &:first-child{
                            span{
                                color: #47CECF;
                                &:first-child{
                                    font-size: 14px;
                                    color: #353535;
                                    font-weight: bold;
                                }
                            }
                        }
                        &:last-child{
                          height: 30px;
                          line-height: 30px;  
                        }
                        span{
                            color: #C2C2C2;
                            font-size: 12px;
                            margin-left: 4%;
                        }
                    }
                }
            }
        }
    }
    .viewsmessages-content-right{
        width: 50%;
        height: 80px;
        text-align: right;
        line-height: 80px;
        label{
            display: flex;
            justify-content: flex-end;
            height: 80px!important;
            text-align: right;
            align-items: center;
            span{
                color: #C2C2C2;
                font-size: 16px!important;
                font-weight: normal!important;
            }
        }
    }
    .untreated>span{
        width: 20%;
        height: 30px;
        line-height: 30px;
        color: #ffffff!important;
        text-align: center;
        background:rgba(71,206,207,1);
        border-radius:3px;
        cursor: pointer;
    }
</style>